using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;

using NUnit.Framework;

using NSimpleDB.Service.VistaDb.QueryProcessing.Compiler;

namespace test.Service.VistaDb.Whitebox
{

    [TestFixture]
    public class test_Sql_Code_Generator
    {
        [Test]
        public void test1PredicateWith1Comp()
        {
            string sql;

            QueryCompiler q = new QueryCompiler();
            
            sql = q.CompileToSql("D0", "['a'='b']");
            Assert.IsTrue(IsSameSql(Properties.Resources.sql1, sql));

            sql = q.CompileToSql("D0", "[not 'a'>='b']");
            Assert.IsTrue(IsSameSql(Properties.Resources.sql2, sql));

            sql = q.CompileToSql("D0", "['a' starts-with 'b']");
            Assert.IsTrue(IsSameSql(Properties.Resources.sql3, sql));
        }


        private bool IsSameSql(string sqlLeft, string sqlRight)
        {
            Console.WriteLine("---");
            Console.WriteLine("***<{0}>", sqlLeft);
            Console.WriteLine("***<{0}>", sqlRight);
            return sqlLeft.Replace(" ", "").ToLower() == sqlRight.Replace(" ", "").ToLower();
        }
    }
}
